#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
using namespace std;
int rd() {int x=0,f=1;char c=getchar();while(!isdigit(c))f=c=='-'?-1:f,c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return x*f;}
const int N=400000;
int n,m,K,a[N],c[N],d[N],f[N][20],g[N][20],win[20][N][2],sum[N];
void Main(int testCaseID) {
    // if(testCaseID!=2) return;
    memset(f,0,sizeof(f));
    memset(g,0,sizeof(g));
    memset(win,0,sizeof(win));
    // rep(i,0,n-1) printf("%d ",a[i]);puts("");
    rep(i,(1<<K),(1<<(K+1))-1) {
        if(i-(1<<K)<=n&&a[i-(1<<K)]<20) f[i][a[i-(1<<K)]]=n-1;
        rep(j,0,K) if(i-(1<<K)>n||j!=a[i-(1<<K)]) f[i][j]=min(n-1,i-(1<<K)-1);
        g[i][0]=f[i][0];rep(j,1,K) g[i][j]=max(f[i][j],g[i][j-1]);
    }
    per(i,(1<<K)-1,1) {
        int t=K-__lg(i);
        rep(j,0,K) {
            f[i][j]=min(g[i*2+d[i]][t-1],f[i*2+!d[i]][j]);
            if(j>=t) f[i][j]=max(f[i][j],f[i*2+d[i]][j]);
        }
        g[i][0]=f[i][0];
        rep(j,1,K) g[i][j]=max(f[i][j],g[i][j-1]);
    }
    // per(i,(1<<(K+1))-1,1) rep(j,K-__lg(i),K) printf("f[%d][%d]=%d\n",i,j,f[i][j]);
    // per(i,(1<<(K+1))-1,1) rep(j,K-__lg(i),K) printf("g[%d][%d]=%d\n",i,j,g[i][j]);
    rep(k,0,K) rep(i,0,(1<<k)-1) {
        if(i<n) {
            int u=i+(1<<K),val=a[i];
            win[k][i][0]=n-1;
            while(u>(1<<(K-k))) {
                if(u/2*2+d[u/2]==u) win[k][i][0]=val>=K-__lg(u)+1?win[k][i][0]:-1;
                else win[k][i][0]=min(win[k][i][0],g[u^1][K-__lg(u)]);
                u/=2;
            }
        }
        {
            int u=i+(1<<K),val=100;
            win[k][i][1]=n-1;
            while(u>(1<<(K-k))) {
                if(u/2*2+d[u/2]==u) win[k][i][1]=val>=K-__lg(u)+1?win[k][i][1]:-1;
                else win[k][i][1]=min(win[k][i][1],g[u^1][K-__lg(u)]);
                u/=2;
            }
        }
    }
    ll ans=0;
    rep(i,1,m) {
        int k=0;
        while((1<<k)<c[i]) k++;
        ll sum=0;
        rep(j,0,(1<<k)-1) if(c[i]-1<=win[k][j][j>=c[i]]) sum+=j+1;
        ans^=1ll*i*sum;
        // printf("sum=%lld\n",sum);
    }
    printf("%lld\n",ans);
}
signed main() {
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    n=rd(),m=rd();
    while((1<<K)<n) K++;
    rep(i,0,n-1) a[i]=rd();
    rep(i,1,m) c[i]=rd();
    rep(i,1,K) {
        string s;cin>>s;
        rep(j,0,(1<<(K-i))-1) d[(1<<(K-i))+j]=s[j]-'0';
    }
    int T=rd();
    rep(i,1,T) {
        int X[4];rep(i,0,3)X[i]=rd();
        rep(i,1,n) a[i-1]^=X[i%4];
        Main(i);
        rep(i,1,n) a[i-1]^=X[i%4];
    }
    return 0;
}
//g++ -std=c++14 -O2 -Wall -fsanitize=address,undefined -o arena arena.cpp
/*#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
using namespace std;
int rd() {int x=0,f=1;char c=getchar();while(!isdigit(c))f=c=='-'?-1:f,c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return x*f;}
const int N=400000;
int n,m,K,a[N],c[N],d[N],f[N][20],g[N][20],win[20][N][2];
ll sum[N];
int bit[N];
void add(int p,int x) {for(p+=10;p<N;p+=p&-p)bit[p]+=x;}
ll ask(int p) {ll s=0;for(p+=10;p;p-=p&-p)s+=bit[p];return s;}
ll ask(int l,int r) {return ask(r)-ask(l-1);}
vector<int> vec[N];
void Main(int testCaseID) {
    // if(testCaseID!=2) return;
    memset(f,0,sizeof(f));
    memset(g,0,sizeof(g));
    memset(win,0,sizeof(win));
    // rep(i,0,n-1) printf("%d ",a[i]);puts("");
    rep(i,(1<<K),(1<<(K+1))-1) {
        if(i-(1<<K)<=n&&a[i-(1<<K)]<20) f[i][a[i-(1<<K)]]=n-1;
        rep(j,0,K) if(i-(1<<K)>n||j!=a[i-(1<<K)]) f[i][j]=min(n-1,i-(1<<K)-1);
        g[i][0]=f[i][0];rep(j,1,K) g[i][j]=max(f[i][j],g[i][j-1]);
    }
    per(i,(1<<K)-1,1) {
        int t=K-__lg(i);
        rep(j,0,K) {
            f[i][j]=min(g[i*2+d[i]][t-1],f[i*2+!d[i]][j]);
            if(j>=t) f[i][j]=max(f[i][j],f[i*2+d[i]][j]);
        }
        g[i][0]=f[i][0];
        rep(j,1,K) g[i][j]=max(f[i][j],g[i][j-1]);
    }
    // per(i,(1<<(K+1))-1,1) rep(j,K-__lg(i),K) printf("f[%d][%d]=%d\n",i,j,f[i][j]);
    // per(i,(1<<(K+1))-1,1) rep(j,K-__lg(i),K) printf("g[%d][%d]=%d\n",i,j,g[i][j]);
    rep(k,0,K) rep(i,0,(1<<k)-1) {
        if(i<n) {
            int u=i+(1<<K),val=a[i];
            win[k][i][0]=n-1;
            while(u>(1<<(K-k))) {
                if(u/2*2+d[u/2]==u) win[k][i][0]=val>=K-__lg(u)+1?win[k][i][0]:-1;
                else win[k][i][0]=min(win[k][i][0],g[u^1][K-__lg(u)]);
                u/=2;
            }
            printf("win[%d][%d][0]=%d\n",k,i,win[k][i][0]);
        }
        {
            int u=i+(1<<K),val=100;
            win[k][i][1]=n-1;
            while(u>(1<<(K-k))) {
                if(u/2*2+d[u/2]==u) win[k][i][1]=val>=K-__lg(u)+1?win[k][i][1]:-1;
                else win[k][i][1]=min(win[k][i][1],g[u^1][K-__lg(u)]);
                u/=2;
            }
            printf("win[%d][%d][1]=%d\n",k,i,win[k][i][1]);
        }
    }
    rep(k,0,K) {
        rep(i,0,n) vec[i].clear();
        memset(bit,0,sizeof(bit));
        rep(i,0,(1<<(k+1))-1) vec[win[k][i][0]+1].push_back(i);
        per(c,n-1,(1<<k)-1) {
            for(int p:vec[c+1]) add(p,p+1),printf("c=%d ! add %d\n",c,p+1);
            if(c+1<(1<<(k+1))) sum[c+1]+=ask(0,c);
        }
        rep(i,0,n) vec[i].clear();
        memset(bit,0,sizeof(bit));
        rep(i,0,(1<<(k+1))-1) vec[win[k][i][1]+1].push_back(i);
        per(c,n-1,(1<<k)-1) {
            for(int p:vec[c+1]) add(p,p+1),printf("c=%d @ add %d\n",c,p+1);
            if(c+1<(1<<(k+1))) sum[c+1]+=ask(c+1,n);
        }
        rep(c,1,n) printf("sum[%d]=%d\n",c,sum[c]);
    }
    ll ans=0;
    rep(i,1,m) {
        int k=0;
        while((1<<k)<c[i]) k++;
        // ll sum=0;
        // rep(j,0,(1<<k)-1) if(c[i]-1<=win[k][j][j>=c[i]]) sum+=j+1;
        ans^=1ll*i*sum[c[i]];
        // printf("sum=%lld\n",sum);
    }
    printf("%lld\n",ans);
}
signed main() {
    // freopen("arena.in","r",stdin);
    // freopen("arena.out","w",stdout);
    n=rd(),m=rd();
    while((1<<K)<n) K++;
    rep(i,0,n-1) a[i]=rd();
    rep(i,1,m) c[i]=rd();
    rep(i,1,K) {
        string s;cin>>s;
        rep(j,0,(1<<(K-i))-1) d[(1<<(K-i))+j]=s[j]-'0';
    }
    int T=rd();
    rep(i,1,T) {
        int X[4];rep(i,0,3)X[i]=rd();
        rep(i,1,n) a[i-1]^=X[i%4];
        Main(i);
        rep(i,1,n) a[i-1]^=X[i%4];
    }
    return 0;
}
//g++ -std=c++14 -O2 -Wall -fsanitize=address,undefined -o arena arena.cpp*/